package osb.map.main;

import com.ljp.ani.R;
import osb.map.net.ClientSocket;
import osb.map.net.DataPackage;
import osb.map.net.DataUser;
import osb.map.net.msgType;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

/**
 * 注册Activity
 * @author Administrator
 *
 */

public class RegisterActivity  extends Activity
{

    public static RegisterActivity public_Static_RegisterActivity;
    private String userId;
    private String userPwd;
    private String userName;
    private int userAccout;


    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mem_register);
        public_Static_RegisterActivity = this;
        
        Button btn_register = (Button)findViewById(R.id.register);
        // 注册按钮
        btn_register.setOnClickListener(new OnClickListener()  
        {
            @Override
            public void onClick(View v)
            {
            	 EditText edit_id = (EditText)findViewById(R.id.ememid);
                 userId = edit_id.getText().toString();

                 EditText edit_pwd = (EditText)findViewById(R.id.emempwd);
                 userPwd = edit_pwd.getText().toString();

                 EditText edit_name = (EditText)findViewById(R.id.ememname);
                 userName = edit_name.getText().toString();

                 userAccout = 0; //初始赠送5元

                 DataPackage data = new DataPackage(msgType.Register_User);
                 data.dataUser = new DataUser(userId, userPwd, userName, userAccout);
                 ClientSocket.Public_Static_ClientSocket.sendMsg(data); 
            }
        });

        Button btn_back = (Button)findViewById(R.id.register_back);
        // 返回按钮
        btn_back.setOnClickListener(new OnClickListener()  
        {
            @Override
            public void onClick(View v)
            {
                RegisterActivity.this.finish();
            }
        });
    }

    /**
     * 注册成功
     */
    public void registerSuccess()
    {
        new AlertDialog.Builder(RegisterActivity.public_Static_RegisterActivity)
        .setMessage("注册成功")
        .setPositiveButton("确定", null).show();
    }
    
    /**
     * 注册失败
     */
    public void registerWrong()
    {
        new AlertDialog.Builder(RegisterActivity.public_Static_RegisterActivity)
        .setTitle("错误").setMessage("注册失败")
        .setPositiveButton("确定", null).show();
    }
	
    /**
	 * menu
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		menu.add(Menu.NONE, Menu.FIRST + 1, 3, "分享下载").setIcon(android.R.drawable.ic_menu_send);
		return true;

	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case Menu.FIRST + 1:
			Intent intent = new Intent();
			intent.setClass(RegisterActivity.this, ShareActivity.class);
			RegisterActivity.this.startActivity(intent);

			break;
		}
		return false;
	}
}
